home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / circusc.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  5KB  |  195 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. unsigned char *circusc_spritebank;
  15. unsigned char *circusc_scroll;
  16. static int flipscreen;
  17.  
  18.  
  19.  
  20. /***************************************************************************
  21.  
  22.   Convert the color PROMs into a more useable format.
  23.  
  24.   Circus Charlie has one 32x8 palette PROM and two 256x4 lookup table PROMs
  25.   (one for characters, one for sprites).
  26.   The palette PROM is connected to the RGB output this way:
  27.  
  28.   bit 7 -- 220 ohm resistor  -- BLUE
  29.         -- 470 ohm resistor  -- BLUE
  30.         -- 220 ohm resistor  -- GREEN
  31.         -- 470 ohm resistor  -- GREEN
  32.         -- 1  kohm resistor  -- GREEN
  33.         -- 220 ohm resistor  -- RED
  34.         -- 470 ohm resistor  -- RED
  35.   bit 0 -- 1  kohm resistor  -- RED
  36.  
  37. ***************************************************************************/
  38. void circusc_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  39. {
  40.     int i;
  41.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  42.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  43.  
  44.  
  45.     for (i = 0;i < Machine->drv->total_colors;i++)
  46.     {
  47.         int bit0,bit1,bit2;
  48.  
  49.         /* red component */
  50.         bit0 = (*color_prom >> 0) & 0x01;
  51.         bit1 = (*color_prom >> 1) & 0x01;
  52.         bit2 = (*color_prom >> 2) & 0x01;
  53.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  54.         /* green component */
  55.         bit0 = (*color_prom >> 3) & 0x01;
  56.         bit1 = (*color_prom >> 4) & 0x01;
  57.         bit2 = (*color_prom >> 5) & 0x01;
  58.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  59.         /* blue component */
  60.         bit0 = 0;
  61.         bit1 = (*color_prom >> 6) & 0x01;
  62.         bit2 = (*color_prom >> 7) & 0x01;
  63.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  64.  
  65.         color_prom++;
  66.     }
  67.  
  68.     /* color_prom now points to the beginning of the lookup table */
  69.  
  70.     /* sprites */
  71.     for (i = 0;i < TOTAL_COLORS(1);i++)
  72.         COLOR(1,i) = *(color_prom++) & 0x0f;
  73.  
  74.     /* characters */
  75.     for (i = 0;i < TOTAL_COLORS(0);i++)
  76.         COLOR(0,i) = (*(color_prom++) & 0x0f) + 0x10;
  77. }
  78.  
  79.  
  80.  
  81. WRITE_HANDLER( circusc_flipscreen_w )
  82. {
  83.     if (flipscreen != (data & 1))
  84.     {
  85.         flipscreen = data & 1;
  86.         memset(dirtybuffer,1,videoram_size);
  87.     }
  88. }
  89.  
  90.  
  91.  
  92. /***************************************************************************
  93.  
  94.   Draw the game screen in the given osd_bitmap.
  95.   Do NOT call osd_update_display() from this function, it will be called by
  96.   the main emulation engine.
  97.  
  98. ***************************************************************************/
  99. void circusc_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  100. {
  101.     int offs;
  102.  
  103.  
  104.     /* for every character in the Video RAM, check if it has been modified */
  105.     /* since last time and update it accordingly. */
  106.     for (offs = videoram_size - 1;offs >= 0;offs--)
  107.     {
  108.         if (dirtybuffer[offs])
  109.         {
  110.             int sx,sy,flipx,flipy;
  111.  
  112.  
  113.             dirtybuffer[offs] = 0;
  114.  
  115.             sx = offs % 32;
  116.             sy = offs / 32;
  117.             flipx = colorram[offs] & 0x40;
  118.             flipy = colorram[offs] & 0x80;
  119.             if (flipscreen)
  120.             {
  121.                 sx = 31 - sx;
  122.                 sy = 31 - sy;
  123.                 flipx = !flipx;
  124.                 flipy = !flipy;
  125.             }
  126.  
  127.             drawgfx(tmpbitmap,Machine->gfx[0],
  128.                     videoram[offs] + 8 * (colorram[offs] & 0x20),
  129.                     colorram[offs] & 0x0f,
  130.                     flipx,flipy,
  131.                     8*sx,8*sy,
  132.                     0,TRANSPARENCY_NONE,0);
  133.         }
  134.     }
  135.  
  136.  
  137.     /* copy the temporary bitmap to the screen */
  138.     {
  139.         int scroll[32];
  140.  
  141.  
  142.         if (flipscreen)
  143.         {
  144.             for (offs = 0;offs < 10;offs++)
  145.                 scroll[31-offs] = 0;
  146.             for (offs = 10;offs < 32;offs++)
  147.                 scroll[31-offs] = *circusc_scroll;
  148.         }
  149.         else
  150.         {
  151.             for (offs = 0;offs < 10;offs++)
  152.                 scroll[offs] = 0;
  153.             for (offs = 10;offs < 32;offs++)
  154.                 scroll[offs] = -*circusc_scroll;
  155.         }
  156.         copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  157.     }
  158.  
  159.  
  160.     /* Draw the sprites. */
  161.     {
  162.         unsigned char *sr;
  163.  
  164.  
  165.         if ((*circusc_spritebank & 0x01) != 0)
  166.             sr = spriteram;
  167.         else sr = spriteram_2;
  168.  
  169.         for (offs = 0; offs < spriteram_size;offs += 4)
  170.         {
  171.             int sx,sy,flipx,flipy;
  172.  
  173.  
  174.             sx = sr[offs + 2];
  175.             sy = sr[offs + 3];
  176.             flipx = sr[offs + 1] & 0x40;
  177.             flipy = sr[offs + 1] & 0x80;
  178.             if (flipscreen)
  179.             {
  180.                 sx = 240 - sx;
  181.                 sy = 240 - sy;
  182.                 flipx = !flipx;
  183.                 flipy = !flipy;
  184.             }
  185.  
  186.             drawgfx(bitmap,Machine->gfx[1],
  187.                     sr[offs + 0] + 8 * (sr[offs + 1] & 0x20),
  188.                     sr[offs + 1] & 0x0f,
  189.                     flipx,flipy,
  190.                     sx,sy,
  191.                     &Machine->drv->visible_area,TRANSPARENCY_COLOR,0);
  192.         }
  193.     }
  194. }
  195.